package org.wlgzs.shop.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.wlgzs.shop.bean.userPhoto;
import org.wlgzs.shop.bean.userPhotoExample;
import org.wlgzs.shop.dao.userPhotoMapper;
import org.wlgzs.shop.service.IUserPhoto;

import java.util.List;


@Service(value = "userPhoto")
public class UserPhotoImpl implements IUserPhoto {
    @Autowired
    userPhotoMapper  photoMapper;

    @Override
    public void upDate(userPhoto date) {
        System.out.println("asdasdasdasd11");
        int userId=date.getId();
        userPhoto userPhoto=selectDate(userId);
        if(userPhoto==null) {
            photoMapper.insert(date);
        }
        else {
            System.out.println("asdasdasdasd");
            userPhotoExample photoExample=new userPhotoExample();
            userPhotoExample.Criteria criteria=photoExample.createCriteria();
            criteria.andIdEqualTo(userPhoto.getId());
            photoMapper.updateByExample(date,photoExample);
        }
    }

    @Override
    public userPhoto selectDate(int userId) {
        userPhotoExample photoExample=new userPhotoExample();
        userPhotoExample.Criteria criteria=photoExample.createCriteria();
        criteria.andIdEqualTo(userId);
        List<userPhoto> date=photoMapper.selectByExample(photoExample);
        if(date==null||date.size()==0){
            return null;
        }
        return date.get(0);
    }
}
